package com.inei.reportedeverificacion.view;

import android.app.ActionBar;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;

import com.inei.reportedeverificacion.R;
import com.inei.reportedeverificacion.tools.MyPageAdapter;

public class Reporte_Activity extends FragmentActivity implements
		ActionBar.TabListener {

	MyPageAdapter myPagerAdapter;
	ViewPager mViewPager;

	Fragment_Seccion_1 fraSec1;
	Fragment_Seccion_2 fraSec2;
	Fragment_Seccion_3 fraSec3;
	Fragment_Seccion_4 fraSec4;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_reporte_1);
		final ActionBar actionBar = getActionBar();
		actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
		myPagerAdapter = new MyPageAdapter(getSupportFragmentManager());
		fraSec1 = new Fragment_Seccion_1();
		fraSec2 = new Fragment_Seccion_2();
		fraSec3 = new Fragment_Seccion_3();
		fraSec4 = new Fragment_Seccion_4();
		//myPagerAdapter.setFragments(fraSec1, fraSec2, fraSec3, fraSec4);

		mViewPager = (ViewPager) findViewById(R.id.pager);
		mViewPager.setAdapter(myPagerAdapter);
		mViewPager
				.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
					@Override
					public void onPageSelected(int position) {
						actionBar.setSelectedNavigationItem(position);
					}
				});

		for (int i = 0; i < myPagerAdapter.getCount(); i++) {
			actionBar.addTab(actionBar.newTab()
					.setText(myPagerAdapter.getPageTitle(i))
					.setTabListener(this));
		}

	}

	@Override
	public void onTabSelected(ActionBar.Tab tab,
			FragmentTransaction fragmentTransaction) {
		mViewPager.setCurrentItem(tab.getPosition());
		try {
			fraSec1.GuardarDatos();
		} catch (Exception e) {
			e.printStackTrace();
		}
		try {
			// fraSec1.guardar();
		} catch (Exception e) {

		}
		try {
			// fraSec1.guardar();
		} catch (Exception e) {

		}
		try {
			// fraSec1.guardar();
		} catch (Exception e) {

		}
	}

	@Override
	public void onTabUnselected(ActionBar.Tab tab,
			FragmentTransaction fragmentTransaction) {
	}

	@Override
	public void onTabReselected(ActionBar.Tab tab,
			FragmentTransaction fragmentTransaction) {
	}

}
